//**********************************************************************
//	File:			SGD_HandleManager.h
//	Author:			Doug Monroe
//	Last Modified:	12/5/12
//	
//	Purpose:		To store data with unique identifiers
//
//**********************************************************************

#ifndef SGD_HANDLEMANAGER_H
#define SGD_HANDLEMANAGER_H


#include "SGD_Handle.h"
#include <vector>
#include <list>

//namespace SGD
//{
	template< typename DataType >
	class CHandleManager
	{
	public:
		CHandleManager	( void );					// Default constructor
		~CHandleManager	( void );					// Destructor

		CHandle			StoreData		( DataType data );
		DataType&		GetData			( CHandle handle ) const;
		DataType		RemoveData		( CHandle handle );

		template< typename TExtraInfo >
		void			ForEach			( bool (*pFunction)( CHandle handle, DataType& data, TExtraInfo* extra ), TExtraInfo* extra ); // const;


	private:
		CHandleManager				( const CHandleManager& );	// Copy constructor
		CHandleManager&	operator=	( const CHandleManager& );	// Assignment operator

		// Type names for data architecture
		typedef std::pair	< CHandle, DataType >		DataPair;
		typedef std::vector	< DataPair >				DataVector;
		typedef std::list	< CHandle >					HandleList;

		// Data Storage:
		DataVector			m_vData;					// Vector of handle-data pairs
		HandleList			m_lFreeIndices;				// Linked-list of empty locations in the vector
	};

//}	// namespace SGD


// Template definitions are within the .hpp
#define	INC_SGD_HANDLE_MANAGER_HPP
#include "SGD_HandleManager.hpp"
#undef	INC_SGD_HANDLE_MANAGER_HPP

#endif //SGD_HANDLEMANAGER_H
